package com.crealth.memcached;

import java.util.List;

import com.crealth.db.ConsumerDb;
import com.crealth.model.ConsumerHouseModel;

public class ConsumerHouseCached {
private static final String houseKeyPrefix = "house_csmid_";
	
	@SuppressWarnings("unchecked")
	public static List<ConsumerHouseModel> selectConsumerHouse(int consumerID) {
		String key = houseKeyPrefix + consumerID;
		Object obj = MemcachedMgr.cachedClient.get(key);
		List<ConsumerHouseModel> housels = null;
		if (obj != null) {
			housels = (List<ConsumerHouseModel>)obj;
		}
		else {
			housels = ConsumerDb.selectConsumerHouse(consumerID);
			if (housels != null) {
				MemcachedMgr.cachedClient.set(key, housels);
			}
		}
		
		return housels;
	}
	
	public static void deleteCached(int consumerID) {
		String key = houseKeyPrefix + consumerID;
		MemcachedMgr.cachedClient.delete(key);
	}
	
	
}
